<!-- 批发寄售订单列表-提交 -->
<template>
  <div class="purchasing-purchase-consignment-submission">
    <el-container class="submission-box">
      <!-- 待确认,已取消,待确认,已拒绝 -->
      <RecordInfo
        :record-form="orderheadercolumns"
        :record-data="topData">
        <template v-slot:recordInfoslot="slotProp">
          <div
            class="solt-info"
          >
            <span class="left-span">
              采购产品总数<span class="right-span">{{ orderInfoForm.purchaseNum }}</span>
            </span>
            <span>
              品种数<span>{{ orderInfoForm.productSpecCount }}</span>
            </span>
            <span>
              总金额 （元）:
              <span ><span class='price'>{{ getFormatterPrice(orderInfoForm.orderMoney) }}</span></span>
            </span>
          </div>
        </template>
      </RecordInfo>
      <!-- 列表模块 -->
      <el-editable
        height="400"
        :data="settlemList"
        :columns="orderreleasecolumns"
      >
        <template
          slot="default-registrationNumber"
          slot-scope="scope">
          <el-button
            :disabled="!scope.row.registrationNumber||!scope.row.registrationNumberId"
            v-html="regisNoButton(scope.row, 'registration')"
            @click="showPdfRegistion(scope.row.registrationNumberId)"
            type="text"
          />
        </template>
      </el-editable>
      <!-- 分页模块 -->
      <el-footer>
        <el-pagination
          align="right"
          style="margin-top:20px;"
          @size-change="sizeChange"
          @current-change="pageChange"
          :page-sizes="page.PAGE_NUMBER"
          :page-size="page.size"
          :current-page="page.page"
          :layout="page.PAGINATION_LAYOUT"
          :total="page.total"
        />
      </el-footer>
    </el-container>
  </div>
</template>

<script>
import RecordZoomCard from '@/moduleComponents/beforeSettle/distributorSide/purchasingManagement/accompaniedbygoods'
import RecordInfo from '@/moduleComponents/beforeSettle/distributorSide/purchasingManagement/record'
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common'
import paginationMixin from '@mixins/paginationMixin'
import ElEditable from '@components/el-editable'
import { formatDate, getFormatterPrice } from '@const/filter.js'
import { hasIn } from 'lodash'
import {
  hossynPssPsOrderYyPssPsNeedOrderGetById,
  hossynPssPsOrderYyPssPsNeedSubmission,
  hossynPssPsOrderYyPssPsNeedOrdergetNeedId,
  hossynPssPsOrderYyPssPsNeedOrdereNeedItem
} from '@const/beforeSettleApi'
import {
  orderheadercolumns,
  orderreleasecolumns,
  receivingGoodsDetail,
  deliveryheadercolumns,
  releasecolumns,
  globalSubmit,
  statusmap,
  ORDER_STATUS_TEXT,
  showPdfRegistion,
  regisNoButton
} from './const'
export default {
  mixins: [paginationMixin],
  data () {
    return {
      releasecolumns,
      flowOrderDialog: false,
      orderheadercolumns,
      deliveryheadercolumns,
      orderreleasecolumns,
      receivingGoodsDetail,
      topData: {},
      topDataoptimization: {},
      page: {
        PAGE_NUMBER,
        PAGINATION_LAYOUT
      },
      dialogPopupVisible: false,
      // 需要根据这个length判断全局按钮的不同显示
      productsCtrLen: 2,
      settlemList: [],
      orderInfoForm: {
        purchaseNum: '',
        productSpecCount: '',
        orderMoney: ''
      }
    }
  },
  components: {
    RecordZoomCard,
    RecordInfo,
    ElEditable
  },
  mounted () {
    this._initGlobalBtn()
    this.getOrderInfo()
    this.getOrderList()
  },
  computed: {
    id () {
      return this.$route.query.id
    },
    purchasStatus () {
      return this.$route.query.purchaseOrderStatus
    }
  },
  methods: {
    getFormatterPrice,
    regisNoButton,
    showPdfRegistion,
    _initGlobalBtn () {
      let obj = {}
      if (this.productsCtrLen > 0) {
        obj = {
          type: 'btn',
          arr: [
            {
              type: 'button',
              noReturn: true,
              val: '返回',
              handle: this.globalCancel
            },
            { type: 'primary', val: '撤销', handle: this.goRevoke },
            { type: 'primary', val: '提交', handle: this.goSubmit },
            { type: 'primary', val: '提交供应商', handle: this.goSupplierSubmit }
          ]
        }
      }
      this.$store.commit('changeLayoutHandle', obj)
    },
    getOrderInfo () {
      this.$axios({
        method: 'post',
        url: hossynPssPsOrderYyPssPsNeedOrderGetById,
        data: {
          id: this.$route.query.id
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        for (let key in obj) {
          if (key === 'orderStatus') {
            obj[key] = ORDER_STATUS_TEXT[obj[key]]
            continue
          }
        }
        this.topData = obj
      })
    },
    getOrderList () {
      this.$axios({
        method: 'post',
        url: hossynPssPsOrderYyPssPsNeedOrdereNeedItem,
        data: {
          id: this.$route.query.id,
          page: this.page.page,
          pageSize: this.page.size
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        this.settlemList = obj.yyPssPsNeedOrderItemVOPageBean.content
        this.page.total = obj.yyPssPsNeedOrderItemVOPageBean.totalElements
        this.orderInfoForm.purchaseNum = obj.purchaseNum
        this.orderInfoForm.productSpecCount = obj.productSpecCount
        this.orderInfoForm.orderMoney = obj.orderMoney
      })
    },
    // 提交
    goSubmit () {
      this.$axios({
        method: 'post',
        url: hossynPssPsOrderYyPssPsNeedOrdergetNeedId,
        data: {
          id: this.$route.query.id,
          orderStatus: 2
        }
      })
        .then(res => {
          let code = hasIn(res, 'data.code') ? res.data.code : ''
          if (code === '0') {
            this.$message({
              type: 'success',
              message: '提交成功'
            })
            this.$router.go(-1)
          } else {
            this.$message({
              type: 'warning',
              message: '提交失败'
            })
          }
        })
        .catch(res => {
          this.$message({
            type: 'warning',
            message: '提交失败'
          })
        })
    },
    goRevoke () {
      this.$axios({
        method: 'post',
        url: hossynPssPsOrderYyPssPsNeedOrdergetNeedId,
        data: {
          id: this.$route.query.id,
          orderStatus: 7
        }
      })
        .then(res => {
          let code = hasIn(res, 'data.code') ? res.data.code : ''
          if (code === '0') {
            this.$message({
              type: 'success',
              message: '撤销成功'
            })
            this.$router.go(-1)
          } else {
            this.$message({
              type: 'warning',
              message: '撤销失败'
            })
          }
        })
        .catch(res => {
          this.$message({
            type: 'warning',
            message: '撤销失败'
          })
        })
    },
    goSupplierSubmit () {
      this.$axios({
        method: 'post',
        url: hossynPssPsOrderYyPssPsNeedSubmission,
        data: {
          id: this.$route.query.id
        }
      })
        .then(res => {
          let code = hasIn(res, 'data.code') ? res.data.code : ''
          if (code === '0') {
            this.$message({
              type: 'success',
              message: '提交供应商成功'
            })
            this.$router.go(-1)
          } else {
            this.$message({
              type: 'warning',
              message: '提交供应商失败'
            })
          }
        })
        .catch(res => {
          this.$message({
            type: 'warning',
            message: '提交供应商失败'
          })
        })
    },
    // 订单信息页码更改
    getItems () {
      this.getOrderList()
    },
    globalCancel () {
      this.$router.go(-1)
    }
  }
}
</script>
<style lang="less">
@import '../m-front-common/pc/assets/var.less';
.purchasing-purchase-consignment-submission {
  height: 100%;
  display: flex;
  flex-direction: column;
  .submission-box {
    flex-direction: column;

    .el-form-item__label {
      width: 110px !important;
    }

    .pagination {
      padding-top: 10px;
      display: flex;
      justify-content: flex-end;
      padding-right: 0;
    }
  }
  .header-limit {
    .el-input__inner {
      width: 200px;
    }
    .el-date-editor {
      width: 368px;
    }
  }
  // .cell {
  //   max-height: 23px !important;
  //   overflow: hidden !important;
  // }
}
</style>
